package com.github.pig.admin.service.attendance.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.github.pig.admin.mapper.attendance.AttendanceTimesMapper;
import com.github.pig.admin.model.attendance.AttendanceRecord;
import com.github.pig.admin.model.attendance.AttendanceTimes;
import com.github.pig.admin.service.attendance.IAttendanceTimesService;
import com.github.pig.common.constant.CommonConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sxf
 * @since 2018-11-22
 */
@Service
public class AttendanceTimesServiceImpl extends ServiceImpl<AttendanceTimesMapper, AttendanceTimes> implements IAttendanceTimesService {
    @Autowired
    private AttendanceTimesMapper timesMapper;
    @Override
    public List<AttendanceRecord> selectByTime(String time,String userName) {
        return timesMapper.selectByTime(time,userName);
    }

    /**
     * 根据IMEI判断是否替换打卡
     * @param time 当前时间  格式yyyy-MM-dd
     * @param imei  设备号
     * @return true可以打开  false 不能打卡
     */
    @Override
    public boolean judgeEquipment(String time, String imei,String userName) {
        List<AttendanceRecord> list = timesMapper.selectByTimeAndIMEI(time,userName,imei);
        if(list!=null && list.size()>0 ){
            return false;
        }
        return true;
    }

    @Override
    public AttendanceTimes getByTime(String time, String username) {
        Wrapper wrapper = new EntityWrapper();
        wrapper.eq(CommonConstant.DEL_FLAG,CommonConstant.STATUS_NORMAL);
        wrapper.eq("attendance_time",time);
        wrapper.eq("user_name",username);
        List<AttendanceTimes> list = timesMapper.selectList(wrapper);
        if(list!=null && list.size()>0){
            return list.get(0);
        }
        return null;
    }
}
